package com.gome.axwl.aoc.service.impl;

import com.gome.axwl.aoc.dao.AppVersionDao;
import com.gome.axwl.aoc.entity.driver.DriverAccount;
import com.gome.axwl.aoc.entity.po.AppVersionPo;
import com.gome.axwl.aoc.service.AppVersionService;
import com.gome.axwl.aoc.service.feign.MasterDataFeignClient;
import com.gome.commons.core.ResultData;
import com.gome.datasource.shard.annotation.ReadDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description: app版本管理
 * @Auther: chengh
 * @Date: 2018/4/25 13:59
 */
@Service("appVersionService")
public class AppServiceServiceImpl implements AppVersionService {

    private final static Logger log = LoggerFactory.getLogger(AppServiceServiceImpl.class);

    @Autowired
    private AppVersionDao appVersionDao;

    @Autowired
    MasterDataFeignClient masterDataFeignClient;

    /**
     * 检测版本号是否存在
     * @param appVersionPo
     * @return
     */
    @ReadDatasource
    @Override
    public long checkVersionIsExist(AppVersionPo appVersionPo) {
        return appVersionDao.checkVersionIsExist(appVersionPo);
    }

    /**
     * 新增版本记录
     * @param appVersionPo
     */
    @Override
    public void insert(AppVersionPo appVersionPo) {
        appVersionDao.insert(appVersionPo);
    }

    /**
     * 根据id查询记录
     * @param id
     * @return
     */
    @ReadDatasource
    @Override
    public AppVersionPo selectById(int id) {
        return appVersionDao.selectByPrimaryKey(id);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void deleteById(int id) {
        appVersionDao.deleteByPrimaryKey(id);
    }

    /**
     * 更新状态
     * @param appVersionPo
     */
    @Override
    public void updateVersionStatus(AppVersionPo appVersionPo) {
        appVersionDao.updateByPrimaryKeySelective(appVersionPo);
    }

    /**
     * 查询列表
     * @return
     */
    @ReadDatasource
    @Override
    public List<AppVersionPo> getListByPage() {
        return appVersionDao.getAll();
    }

    /**
     * 查询比指定系统、指定版本号更大的版本信息集合
     * @param versionSystemType
     * @param versionCode
     * @return
     */
    @ReadDatasource
    @Override
    public List<AppVersionPo> getBiggerVersion(String versionSystemType, String versionCode) {
        Integer versionCodeInt = Integer.parseInt(versionCode);
        return appVersionDao.getBiggerVersion(versionSystemType, versionCodeInt, "1");  //当前系统已发布的比当前版本大的版本
    }

    /**
     * 获取用户的DC编码
     * @param accountNo
     * @return
     */
    @Override
    public ResultData getDcCodeByAccountNo(String accountNo) {
        return masterDataFeignClient.getDcCodeByAccountNo(accountNo);
    }

    /**
     * 查询DC信息集合
     * @param list
     * @return
     */
    @Override
    public ResultData<Map<String,Object>> getDcByDcCodes(List<String> list) {
        return masterDataFeignClient.getDcByDcCodes(list);
    }

    /**
     * 获取dc下的司机
     * @param list
     * @return
     */
    @Override
    public ResultData<List<DriverAccount>> getDriversByDcCodes(List<String> list) {
        return masterDataFeignClient.getDriversByDcCodes(list);
    }
}
